﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ledict.ConditionExtract.BLL;
using Ledict.ConditionExtract.Common;
using Ledict.ConditionExtract.Model;
namespace Ledict.ConditionExtract
{
    public partial class WB_AddSynonyms : Form
    {
        public WB_AddSynonyms()
        {
            InitializeComponent();
        }
       public string WBS_ID = "";
       public string WBS_SynonymWords = "";
        NewIDBLL newid = new NewIDBLL();
        WordBankSynonymBLL wordbanksynonymbll = new WordBankSynonymBLL();
        private void Save_Click(object sender, EventArgs e)
        {
            try
            {
                SYS_WordBank_Synonym model = new SYS_WordBank_Synonym();
                if (WBS_ID == "")//新增
                {
                    string[] WordsTextArr = WordsText.Text.Split(';','；');
                    foreach (var item in WordsTextArr)
                    {
                        model.WBS_ID = newid.JudgeDoc_CreateID("SYS_WordBank_Synonym");
                        model.WBS_SynonymWords =item ;
                        if (model.WBS_SynonymWords != "")
                        {
                           if( wordbanksynonymbll.Add(model))
                            MessageBox.Show("保存成功!");
                        }
                    }
                }
                else//更新
                {
                    model.WBS_ID = WBS_ID;
                    model.WBS_SynonymWords = WordsText.Text;
                    if (model.WBS_SynonymWords != "")
                    {
                        if(wordbanksynonymbll.Update(model))
                        MessageBox.Show("保存成功!");
                    }
                }
            }
            catch (Exception error)
            {
                MessageBox.Show("保存失败!");
            }
            WB_Manage_Synonyms wb_manage = WB_Manage_Synonyms.Default;
            wb_manage.ShowSynonym();
            this.Close();
        }

        private void Clear_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void WB_AddSynonyms_Load(object sender, EventArgs e)
        {
            if (WBS_ID != "")
            {
                WordsText.Text = WBS_SynonymWords;
            }
        }
    }
}
